<dl style="margin:10px 10px 5px; height:22px" class="clear">
  <dt class="left alR " style="width:150px;">推荐（1=是， 0=否）：</dt><dd class="left alL"><input type="text" id="recommend" value="{$tag['recommend']}"></dd>
  <dt class="left alR " style="width:70px;">名称：</dt><dd class="left alL"><input type="text" id="tag_name" value="{$tag['tag_name']}"></dd>
</dl>
<div style="background:#F8F8F8; border-top:1px solid #E6E6E6; padding:5px;" class="alR">
  <php>if (isset($tag)) {</php>
  <input type="button" class="btn_b" onclick="doeditTag()" value="确定" />
  <php>}else {</php>
  <input type="button" class="btn_b" onclick="doaddTag()" value="确定" />
  <php>}</php>
  <input type="button" class="btn_w" onclick="cancel()" value="取消" />
</div>
<script type="text/javascript">

//添加地区
function doaddTag() {
	var tag_name = $('#tag_name').val();
	var recommend   = $('#recommend').val();
	var vv =recommend?'是':'否';
	if(tag_name=='') {
		ui.error('请输入名称');
		return ;
	}

	//提交添加
	$.post("{:U('admin/Blog/doAddTag')}", {tag_name:tag_name,recommend:recommend}, function(res){
	    if (res == 2) {
			ui.box.close();
			ui.error('标签已存在');
	        
        }else if(res == 0){
			ui.error('添加失败');
		}else {
        	//var url = "{:U('admin/Shop/typelist')}";
            var html = '';
            html += '<tr overstyle="on" id="tag_'+res+'">';
            html += '<td><input type="checkbox" name="checkbox" id="checkbox2" onclick="checkon(this)" value="'+res+'"></td>';
            html += '<td>'+res+'</td>';
			html += '<td>'+tag_name+'</td>';
            html += '<td><div style="float:left">'+vv+'</div></td>';
            html += '<td><a href="javascript:void(0);" onclick="editTag('+res+');">编辑</a> ';
            html += '<a href="javascript:void(0);" onclick="del('+res+');">删除</a> </td>';
            html += '</tr>';
            $('#tag_list').prepend(html);
            ui.success('添加成功');
			ui.box.close();
		}
	});
}

//编辑地区
function doeditTag() {
	var tag_name= $('#tag_name').val();
	var tag_id	= "{$tag['tag_id']}";
	var recommend=$('#recommend').val();
	var vv = recommend?'是':'否';
	if(tag_name=='') {
        ui.error('请输入名称');
        return ;
    }
	
	//判断名称是否有变化
	if(tag_name == "{$tag['tag_name']}" && recommend == "{$tag['recommend']}") {
		ui.success('无变化，未提交修改');
		ui.box.close();
		return false;
	}

	//判断是否有重名
	$.post("{:U('admin/Blog/doEditTag')}", {tag_id:tag_id, recommend:recommend, tag_name:tag_name}, function(res){
		if (res == 0) {
            ui.error('保存失败');
        }else {
			
        	$('#tag_name'+tag_id).html(tag_name);
			$('#recommend_'+tag_id).html(vv);
            ui.success('保存成功');
            ui.box.close();
        }
	});
}

function cancel() {
	ui.box.close();
}
</script>
